// pages/common/withdraw-cash.js
const app = getApp()
const info = {}
var common = require('../../utils/mr_xu/common.js')

Page({
  data: {
    MEMBER_DRAW_COUNT_MAX: '',
    MEMBER_DRAW_MONEY_MAX: ''
  },
  onLoad: function(options) {
    this.setData({
      MEMBER_DRAW_COUNT_MAX: common.getConfig('MEMBER_DRAW_COUNT_MAX'),
      MEMBER_DRAW_MONEY_MAX: common.getConfig('MEMBER_DRAW_MONEY_MAX')
    })
    this.setData(options)
    app.http.post('rest/member/queryById.do').then(res => {
      this.setData({
        total: res.obj.money ? res.obj.money : 0
      })
      wx.hideLoading()
      wx.stopPullDownRefresh()
    }).catch(err => {
      app.wxToast.error(err.msg)
    })
  },

  onInput(e) {
    let value = e.detail.value
    console.log(value)
    if (parseInt(value) > parseInt(this.data.MEMBER_DRAW_MONEY_MAX)) {
      value = parseInt(this.data.MEMBER_DRAW_MONEY_MAX)
    }
    this.setData({
      allMoney:value
    })
    info[e.currentTarget.dataset.key] = value
  },
  allTx() {
    this.setData({
      allMoney: this.data.total
    })
    info['amount'] = this.data.total
  },
  submit() {
    if (!info.amount) {
      app.wxToast.error('请输入提现金额')
      return
    }
    info.amount = parseFloat(info.amount)
    if (info.amount <= 0 || info.amount > +this.data.total) {
      app.wxToast.error('请输入正确的提现金额')
      return
    }

    wx.showLoading({
      title: '加载中...',
    })
    app.http.post('rest/member/draw.do', {
      data: info.amount + ''
    }).then(res => {
      wx.hideLoading()
      wx.showModal({
        title: '温馨提示',
        content: '提现申请已提交，提现金额将在24小时内到账 请注意查收',
        showCancel: false,
        confirmColor: '#2691DF',
        success: res => {
          wx.navigateBack({})
        }
      })
    }).catch(err => {
     
    })
  },
})